
import React, { Component } from 'react';
import {getNamesByPath} from './utils/breads.utils';
import {connect} from 'react-redux';
import {menuSetBread,addBread} from './../actions';
import routes from './../router';

import Layout from './layout';

class App  extends Component {

    constructor(props){
        super(props);
        this.setBreads = this.setBreads.bind(this);
        this.autoRoute = this.autoRoute.bind(this);
        this.autoRoute();
    }

    componentDidMount(){
       setTimeout(()=>{
        this.setBreads();
       },0);
      
    }

    autoRoute(){

        let rHistory = this.props.history;
        let rLocation = this.props.location;
        // console.log(rLocation);
        if(rLocation.pathname != '/'){

        }else{
            rHistory.replace({
                pathname:routes[0].path
            });
        };
       
    }


    /**
     * 当刷新的时候设置当前路径的bread
     */
    setBreads(){
        let arrs = getNamesByPath(this.props.location.pathname);
        // console.log(this.props.location.pathname);
        this.props.menuSetBread(arrs);
    }

    state = {  }
    render() {
        return (
           <Layout />
         );
    }
}
App = connect(()=>({}),{
    menuSetBread,
    addBread
})(App);
export default App;

